package com.example.control;


import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.control.adapter.MenuAdapter;
import com.example.control.bean.MenuResponse;
import com.google.android.material.navigation.NavigationView;
import com.google.gson.Gson;

import java.util.List;

public class DrawerActivity extends BaseActivity {

    private DrawerLayout drawerLayout;//滑动菜单
    private Toolbar toolbar;
    //导航视图
    private NavigationView navView;
    private RecyclerView rvMenu;//列表
//    private MenuAdapter menuAdapter;
    private List<MenuResponse.DataBean> data;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawer);
        transparentStatusBar();
        drawerLayout = findViewById(R.id.drawer_layout);
        toolbar = findViewById(R.id.toolbar);
        toolbar.setNavigationOnClickListener(v -> {
            drawerLayout.openDrawer(GravityCompat.START);
        });

        navView = findViewById(R.id.nav_view);
        //获取头部视图
        View headerView = navView.getHeaderView(0);
        headerView.findViewById(R.id.iv_avater).setOnClickListener(v->showMsg("头像"));
//        rvMenu = headerView.findViewById(R.id.rv_menu);

        //导航菜单点击
//        navView.setNavigationItemSelectedListener(item->{
//            switch (item.getItemId()){
//                case R.id.item_friend:
//                    showMsg("朋友");
//                    break;
//
//                case R.id.item_wallet:
//                    showMsg("钱包");
//                    break;
//
//                case R.id.item_location:
//                    showMsg("位置");
//                    break;
//
//                case R.id.item_phone:
//                    showMsg("电话");
//                    break;
//
//                case R.id.item_email:
//                    showMsg("邮箱");
//                    break;
//                case R.id.item_share:
//                    showMsg("分享");
//                    break;
//                case R.id.item_send:
//                    showMsg("发送");
//                    break;
//                default:
//                    break;
//            }
//            //关闭滑动菜单
//            drawerLayout.closeDrawer(GravityCompat.START);
//            return true;
//        });


    }

    /**
     * 透明状态栏
     */
    private void transparentStatusBar() {
        //改变状态栏颜色为透明
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }

    /**
     * 显示菜单列表
     */
//    private void showMenuList(){
//        //解析Gson数据
//        MenuResponse menuResponse = new Gson().fromJson(Contanst.JSON, MenuResponse.class);
//        if(menuResponse.getCode() == Contanst.SUCCESS){
//            //为空处理
//            if(menuResponse.getData() == null){
//                showMsg("数据为空");
//                return;
//            }
//            data = menuResponse.getData();
//            //设置适配器和数据源
//            menuAdapter = new MenuAdapter(R.layout.item_menu, data);
//
//            //item点击事件
//            menuAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
//                @Override
//                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                    showMsg(data.get(position).getName());
//                    //关闭滑动菜单
//                    drawerLayout.closeDrawer(GravityCompat.START);
//                }
//            });
//            //设置线性布局，默认是纵向
//            rvMenu.setLayoutManager(new LinearLayoutManager(this));
//            //设置适配器
////            rvMenu.setAdapter(menuAdapter);
//            //添加item的分隔线
//            rvMenu.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
//
//        }
//    }
}